home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Simple YACC question...
- Date: 25 Feb 1996 12:37:52 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4gqhb0INN2t7@keats.ugrad.cs.ubc.ca>
- References: <jeffy.824950099@eng2.iastate.edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <jeffy.824950099@eng2.iastate.edu>,
- Jeffrey A Echtenkamp <jeffy@iastate.edu> wrote:
-
- This is not really a topic for comp.lang.c, but I can't think of any
- appropriate newsgroup, so this might as well be it!
-
- >I have a very simple yacc grammar, which gives the following warnings
- >under gnu bison:
-
- Does it give warnings under yacc? Yacc is the ``standard''. :) Btw, there are
- newsgroups specifically for discussing GNU tools. Do you have the excellent
- Bison documentation?
-
- >test.y:9: warning: type clash ('' 'buffer') on default action
- >test.y:9: warning: type clash ('' 'buffer') on default action
- >
- >
- >Here's the code:
- >
- >
- >%{
- >%}
- >%union
- >{
- > char buffer[1000];
- >}
- >%token <buffer> STRING
- >%%
- >STRINGS: STRING | STRING '.' STRINGS;
- >%%
-
- You forgot to specify an action for the production for "STRING". The default
- one inserted by bison is apparently not compatible with they way you have
- attributed the STRINGS nonterminal.
-
- As a rule, as soon as you introduce types for your non-terminals, you should
- provide an action to all your productions, perhaps one which assigns
- something meaningful to $$.
-
- Either that, or (for now) drop the type specifier from STRING, and name it as
- %token STRING instead. When your grammar is ready for actions, you can type
- your non-terminials at the same time.
-
- By the way, you don't have to shout to yacc or bison! While non-terminal
- symbols are frequently given in upper case, non-terminals (such as "strings")
- are named in lower case. It's just a sort of convention, but it does help you
- pick apart the two kinds of symbol.
-
- >
- >There's alot more to the code than this, but I was able to reduce
- >my error down to these 10 lines and still generate the error.
- >The basic thing I want to say is, a "STRINGS" is either a STRING
- >or several strings separated by .
-
- In that case, do add the two actions:
-
- strings
- : STRING . strings
- {
- /* do something */
- }
- | STRING
- {
- /* do something */
- }
- ;
-
- Also note: the grammar you have written stands to blow the yacc stack during
- parsing. Make it left recursive instead:
-
- strings
- : strings . STRING
- | STRING
- ;
-
- This way, yacc will be able to make the reduction strings -> STRING early on.
- In the right-recursive model, the reductions won't happen until you see the
- very last STRING in sequence, thus building up the parsing stack needlessly.
-
- >Please respond via email if possible.
-
- CC added.
-
- >Thanks!
-
- No problem.
-
- --
- The Kazinator, Master Yaccster.
- --
-
-